#version 300 es

#ifdef GL_ES
precision mediump float;
#endif

#define TWO_PI 6.28318530718

uniform vec2 u_resolution;
uniform float u_time;

//  Function from Iñigo Quiles
//  https://www.shadertoy.com/view/MsS3Wc
vec3 hsb2rgb(in vec3 c) {
  vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
  rgb = rgb * rgb * (3.0 - 2.0 * rgb);
  return c.z * mix(vec3(1.0), rgb, c.y);
}

out vec4 outColor;

void main() {

  float solution = min(u_resolution.x, u_resolution.y);
  vec2 st = (u_resolution / 2.0 - gl_FragCoord.xy) / solution;
  vec2 s = vec2(1.0, 1.0) - step(0.5, abs(st));
  if(s.x * s.y < 0.00001 || dot(st, st) > 0.25) {
    discard;
  }

  vec3 color = vec3(0.0);
  float angle = atan(st.y, st.x);
  float radius = length(st) * 2.0;

    // Map the angle (-PI to PI) to the Hue (from 0 to 1)
    // and the Saturation to the radius
  color = hsb2rgb(vec3((angle / TWO_PI) + 0.5, radius, 1.0));

  outColor = vec4(color, smoothstep(1.0, 0.99, radius));
}
